package procsim;

import java.awt.*;

public class GALU extends ALU implements GraphicalElement {

    private int width = 248;
    private int height = 120;
    private int x, y;

    public GALU(int num, MSignal in1, MSignal in2) {
        super(num, in1, in2);
    }

    @Override
    public void setCoords(int x, int y){
        this.x = x;
        this.y = y;
    }

    @Override
    public int getWidth() {
        return width;
    }

    @Override
    public int getHeight() {
        return height;
    }

    @Override
    public void setSize(int width, int height) {
        this.width = width;
        this.height = height;
    }

    @Override
    public void drawIt(Graphics2D g, int x, int y) {
        Util.saveGraphics(g);
        g.setColor(Color.BLACK);
        g.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
        g.drawPolygon(new int[]{x+1, x+63, x+93, x+156, x+186, x+247, x+206, x+42}, new int[]{y+1, y+1, y+65, y+65, y+1, y+1, y+119, y+119}, 8);
        g.drawString("A", x+30, y+13);
        g.drawString("B", x+width-35, y+13);
        g.drawString("F", x+width/2-5, y+height-3);
        g.drawString("add", x+14, y+30);
        g.drawString("and", x+22, y+53);
        g.drawString("trans", x+29, y+73);
        g.drawString("Cout", x+36, y+95);
        g.drawString("inc", x+width-34, y+30);
        g.drawString("dec", x+width-42, y+53);
        g.drawString("asr", x+width-49, y+74);
        g.drawString("C0", x+width-50, y+96);
        g.setFont(new Font(Font.MONOSPACED, Font.BOLD, 16));
        g.drawString("ALU", x+width/2-15, y+height-25);
        Util.restoreGraphics(g);
    }

    @Override
    public void drawIt(Graphics2D g) {
        drawIt(g, x, y);
    }

    public Coords getInACoords(int length){
        return new Coords(x+33, y-length, x+33, y);
    }

    public Coords getInBCoords(int length){
        return new Coords(x+getWidth()-33, y-length, x+getWidth()-33, y);
    }

    public Coords getResCoords(int length){
        return new Coords(x+getWidth()/2-3, y+getHeight()+1, x+getWidth()/2-3, y+getHeight()+length);
    }

    public Coords getAddCoords(int length){
        return new Coords(x-length, y+27, x+9, y+27);
    }

    public Coords getAndCoords(int length){
        return new Coords(x-length, y+49, x+17, y+49);
    }

    public Coords getTransCoords(int length){
        return new Coords(x-length, y+71, x+24, y+71);
    }

    public Coords getCoutCoords(int length){
        return new Coords(x-length, y+92, x+32, y+92);
    }

    public Coords getIncCoords(int length){
        return new Coords(x+getWidth()+length, y+27, x+getWidth()-9, y+27);
    }

    public Coords getDecCoords(int length){
        return new Coords(x+getWidth()+length, y+49, x+getWidth()-17, y+49);
    }

    public Coords getAsrCoords(int length){
        return new Coords(x+getWidth()+length, y+71, x+getWidth()-25, y+71);
    }

    public Coords getCoCoords(int length){
        return new Coords(x+getWidth()+length, y+92, x+getWidth()-32, y+92);
    }
}
